//
//  Status.swift
//  XinLangWeibo10
//
//  Created by 白利兵 on 15/10/19.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

class Status: NSObject {
    // 微博ID
    var id: Int = 0
    // 来源
    var source: String?
    // 创建时间
    var created_at: String?
    // 内容
    var text: String?
    // 用户模型
    var user: User?
    // 缩略图配图数组
    var pic_urls: [[String: String]]? //pic_urls
    // 转发模型
    var retweeted_status: Status?
    // 构造数据模型
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    // 重写kvc
    override func setValue(value: AnyObject?, forKey key: String) {
        // 判断是否为user
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = User(dict: dict)
            }
            return
        }
        // 判断 key 是否是 retweeted_status
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = Status(dict: dict)
            }
            return
        }
        super.setValue(value, forKey: key)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    // 重写description方法
    override var description: String {
        // 定义字典键值对
        let keys = ["id","source","created_at","text","user","pic_urls","retweeted_status"]
        // 返回模型转字典的数据
        return dictionaryWithValuesForKeys(keys).description
    }
}
